package edu.xhu.communityantiepidemicsystemback.common.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

@Configuration
public class CorsWebConfig {

    @Bean
    public CorsFilter corsFilter(){
        UrlBasedCorsConfigurationSource source=new UrlBasedCorsConfigurationSource();
        CorsConfiguration corsConfiguration=new CorsConfiguration();
        corsConfiguration.setAllowCredentials(true);//允许验证信息跨域
        corsConfiguration.addAllowedOriginPattern("*");//允许哪些请求源跨域,*通配符
        corsConfiguration.addAllowedHeader("*");//允许哪些头信息跨域
        corsConfiguration.addAllowedMethod("*");//允许哪些方法跨域
        source.registerCorsConfiguration("/**",corsConfiguration);//跨域配置装入配置源
        return new CorsFilter(source);
    }
}
